/*
The MIT License

Copyright (c) 2011 Sean M. Thomas

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/

#ifndef FS_FS_OBJECT
#define FS_FS_OBJECT

#ifdef _WIN32
#include <windows.h>
#endif

#include <GL/glew.h>
#include <GL/gl.h>
#include <glm.hpp>
#include <vector>

#include "fs_Mesh.h"
#include "sphere.h"

#include "aiScene.h"

#include "fs_containers.h"

using namespace glm;
using namespace std;

/**
	The object class is created by specifying the objPath and objName.
	It is a container for meshes, which represent drawable objects.
*/
class fs_Object {
private:
	vector<fs_Mesh*> meshes;
	int *numCopies;
	int textureCount;
	unsigned int ssFlags;

	mat4 model;
	mat4 lastModel, animModel, currentModel;
	bool animated;

	unsigned int ID;

	void loadMeshFromAiScene(unsigned int meshNumber, const aiScene *scene, string filePath);

public:
	fs_Object(const char *filePath, const char *fileName);
	fs_Object(fs_Object *existingObject);
	fs_Object(fs_device_mesh deviceMesh);
	~fs_Object();

	void setModelTransform(mat4 newModel);
	void scale(float scaleFactor, bool append = false);
	void rotate(float angle, vec3 axis, bool append = false);
	void draw(fs_first_pass_draw_options settings);
	void translate(vec3 trans, bool append = false);
	void setIdentity();

	void animate(float rotationAngle, float distance, vec3 up = vec3(.0f,.0f,1.0f), vec3 zeroAngleVector = vec3(.0f,1.0f,.0f));
};

#endif // #ifndef FS_FS_OBJECT